package com.nowcoder.community.util;

import com.nowcoder.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * 持有用户信息,用于代替session对象.
 */
@Component
public class UserThreadLocal {

    private static final ThreadLocal<User> LOCAL = new ThreadLocal<>();

    public static void setUser(User user) {
        LOCAL.set(user);
    }

    public static User getUser() {
        return LOCAL.get();
    }

    public static void remove() {
        LOCAL.remove();
    }

}
